package com.project.xy;

import java.util.Scanner;

public class Test {
    private static Scanner scanner = new Scanner(System.in);
    private static GradeManager gradeManager = new GradeManager();

    public static void main(String[] args) {
        while (true) {
            showMenu();
            int choice = scanner.nextInt();
            scanner.nextLine(); // 清除缓冲区

            switch (choice) {
                case 1:
                    recordGrade();
                    break;
                case 2:
                    queryGrade();
                    break;
                case 3:
                    statisticsGrade();// 统计课程成绩
                    break;
                case 4:
                    exitSystem();
                    return;
                default:
                    System.out.println("无效的选项，请重新输入！");
            }
        }
    }


    // 显示菜单
    private static void showMenu() {
        System.out.println("=================================");
        System.out.println("欢迎使用学生成绩管理系统");
        System.out.println("=================================");
        System.out.println("请选择操作：");
        System.out.println("1. 记录学生成绩");
        System.out.println("2. 查询学生成绩");
        System.out.println("3. 统计课程成绩");
        System.out.println("4. 退出系统");
        System.out.print("请输入选项序号：");
    }

    // 记录学生成绩
    private static void recordGrade() {
        System.out.println("\n===== 记录学生成绩 =====");
        System.out.print("请输入学生姓名：");
        String name = scanner.nextLine();
        System.out.print("请输入学生学号：");
        String id = scanner.nextLine();
        System.out.print("请输入课程名称：");
        String course = scanner.nextLine();
        System.out.print("请输入成绩（0-100）：");
        double grade = scanner.nextDouble();
        scanner.nextLine(); // 清除缓冲区

        if (grade < 0 || grade > 100) {
            System.out.println("成绩输入无效，请输入0-100之间的数字！");
        } else {
            StudentGrade studentGrade = new StudentGrade(name, id, course, grade);
            gradeManager.addGrade(studentGrade);
        }
    }

    // 查询学生成绩
    private static void queryGrade() {
        System.out.println("\n===== 查询学生成绩 =====");
        System.out.println("请选择查询方式：");
        System.out.println("1. 按学生姓名查询");
        System.out.println("2. 按学生学号查询");
        System.out.println("3. 按课程名称查询");
        System.out.print("请输入选项序号：");
        int queryChoice = scanner.nextInt();
        scanner.nextLine(); // 清除缓冲区

        switch (queryChoice) {
            case 1:
                System.out.print("请输入学生姓名：");
                String queryName = scanner.nextLine();
                gradeManager.queryByName(queryName);
                break;
            case 2:
                System.out.print("请输入学生学号：");
                String queryId = scanner.nextLine();
                gradeManager.queryById(queryId);
                break;
            case 3:
                System.out.print("请输入课程名称：");
                String queryCourse = scanner.nextLine();
                gradeManager.queryByCourse(queryCourse);
                break;
            default:
                System.out.println("无效的查询选项，请重新选择！");
        }
    }

    // 统计课程成绩
    private static void statisticsGrade() {
        System.out.println("\n===== 统计课程成绩 =====");
        System.out.print("请输入课程名称：");
        String course = scanner.nextLine();
        gradeManager.statisticsByCourse(course);
    }

    // 退出系统
    private static void exitSystem() {
        System.out.println("\n感谢使用学生成绩管理系统，再见！");
    }
}//a